﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Web;
using System.IO;
using System.Net;   
using System.Text.RegularExpressions;

namespace scapeinStats
{
    public partial class Lookup : Form
    {
        //userInfo uI = new userInfo();
        public userInfo constitutionskill;
        public userInfo constructionskill;
        public userInfo cookingskill;
        public userInfo craftingskill;
        public userInfo defenceskill;
        public userInfo dungeoneeringskill;
        public userInfo farmingskill;
        public userInfo firemakingskill;
        public userInfo fishingskill;
        public userInfo fletchingskill;
        public userInfo herbloreskill;
        public userInfo hunterskill;
        public userInfo magicskill;
        public userInfo miningskill;
       // private userInfo OLO;
        public userInfo overallLevel; //= new userInfo();
        public userInfo prayerskill;
        public userInfo rangeskill;
        public userInfo runecraftingskill;
        public userInfo slayerskill;
        public userInfo smithingskill;
        public userInfo strengthskill;
        public userInfo summoningskill;
        public userInfo thievingskill;
        public userInfo woodcuttingskill;
        public userInfo agilityskill;
        public userInfo attackskill;

        public Lookup()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            var RSN = txtUsername.Text;
            try
            {
                             
                Cursor.Current = Cursors.WaitCursor;
                WebClient client = new WebClient();
                StreamReader reader = new StreamReader(client.OpenRead("http://hiscore.runescape.com/index_lite.ws?player=" + RSN));

                string[] strArray17 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                overallLevel = new userInfo();
                overallLevel.Rank = Conversions.ToInteger(strArray17[0]);
                overallLevel.Level = Conversions.ToInteger(strArray17[1]);
                overallLevel.EXP = Conversions.ToInteger(strArray17[2]);

                string[] strArray2 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                attackskill = new userInfo();
                attackskill.Rank = Conversions.ToInteger(strArray2[0]);
                attackskill.Level = Conversions.ToInteger(strArray2[1]);
                attackskill.EXP = Conversions.ToInteger(strArray2[2]);
  
                string[] strArray7 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 defenceskill = new userInfo();
                defenceskill.Rank = Conversions.ToInteger(strArray7[0]);
                defenceskill.Level = Conversions.ToInteger(strArray7[1]);
                defenceskill.EXP = Conversions.ToInteger(strArray7[2]);
        
                string[] strArray23 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 strengthskill = new userInfo();
                strengthskill.Rank = Conversions.ToInteger(strArray23[0]);
                strengthskill.Level = Conversions.ToInteger(strArray23[1]);
                strengthskill.EXP = Conversions.ToInteger(strArray23[2]);

                string[] strArray3 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 constitutionskill = new userInfo();
                constitutionskill.Rank = Conversions.ToInteger(strArray3[0]);
                constitutionskill.Level = Conversions.ToInteger(strArray3[1]);
                constitutionskill.EXP = Conversions.ToInteger(strArray3[2]);
             
                string[] strArray19 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 rangeskill = new userInfo();
                rangeskill.Rank = Conversions.ToInteger(strArray19[0]);
                rangeskill.Level = Conversions.ToInteger(strArray19[1]);
                rangeskill.EXP = Conversions.ToInteger(strArray19[2]);
            
                string[] strArray18 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 prayerskill = new userInfo();
                prayerskill.Rank = Conversions.ToInteger(strArray18[0]);
                prayerskill.Level = Conversions.ToInteger(strArray18[1]);
                prayerskill.EXP = Conversions.ToInteger(strArray18[2]);
             
                string[] strArray15 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 magicskill = new userInfo();
                magicskill.Rank = Conversions.ToInteger(strArray15[0]);
                magicskill.Level = Conversions.ToInteger(strArray15[1]);
                magicskill.EXP = Conversions.ToInteger(strArray15[2]);

                string[] strArray5 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 cookingskill = new userInfo();
                cookingskill.Rank = Conversions.ToInteger(strArray5[0]);
                cookingskill.Level = Conversions.ToInteger(strArray5[1]);
                cookingskill.EXP = Conversions.ToInteger(strArray5[2]);
              
                string[] strArray26 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 woodcuttingskill = new userInfo();
                woodcuttingskill.Rank = Conversions.ToInteger(strArray26[0]);
                woodcuttingskill.Level = Conversions.ToInteger(strArray26[1]);
                woodcuttingskill.EXP = Conversions.ToInteger(strArray26[2]);
          
                string[] strArray12 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 fletchingskill = new userInfo();
                fletchingskill.Rank = Conversions.ToInteger(strArray12[0]);
                fletchingskill.Level = Conversions.ToInteger(strArray12[1]);
                fletchingskill.EXP = Conversions.ToInteger(strArray12[2]);
          
                string[] strArray11 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 fishingskill = new userInfo();
                fishingskill.Rank = Conversions.ToInteger(strArray11[0]);
                fishingskill.Level = Conversions.ToInteger(strArray11[1]);
                fishingskill.EXP = Conversions.ToInteger(strArray11[2]);
           
                string[] strArray10 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 firemakingskill = new userInfo();
                firemakingskill.Rank = Conversions.ToInteger(strArray10[0]);
                firemakingskill.Level = Conversions.ToInteger(strArray10[1]);
                firemakingskill.EXP = Conversions.ToInteger(strArray10[2]);
      
                string[] strArray6 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 craftingskill = new userInfo();
                craftingskill.Rank = Conversions.ToInteger(strArray6[0]);
                craftingskill.Level = Conversions.ToInteger(strArray6[1]);
                craftingskill.EXP = Conversions.ToInteger(strArray6[2]);
       
                string[] strArray22 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 smithingskill = new userInfo();
                smithingskill.Rank = Conversions.ToInteger(strArray22[0]);
                smithingskill.Level = Conversions.ToInteger(strArray22[1]);
                smithingskill.EXP = Conversions.ToInteger(strArray22[2]);
             
                string[] strArray16 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 miningskill = new userInfo();
                miningskill.Rank = Conversions.ToInteger(strArray16[0]);
                miningskill.Level = Conversions.ToInteger(strArray16[1]);
                miningskill.EXP = Conversions.ToInteger(strArray16[2]);
                
                string[] strArray13 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 herbloreskill = new userInfo();
                herbloreskill.Rank = Conversions.ToInteger(strArray13[0]);
                herbloreskill.Level = Conversions.ToInteger(strArray13[1]);
                herbloreskill.EXP = Conversions.ToInteger(strArray13[2]);
               
                string[] strArray = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 agilityskill = new userInfo();
                agilityskill.Rank = Conversions.ToInteger(strArray[0]);
                agilityskill.Level = Conversions.ToInteger(strArray[1]);
                agilityskill.EXP = Conversions.ToInteger(strArray[2]);
               
                string[] strArray25 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 thievingskill = new userInfo();
                thievingskill.Rank = Conversions.ToInteger(strArray25[0]);
                thievingskill.Level = Conversions.ToInteger(strArray25[1]);
                thievingskill.EXP = Conversions.ToInteger(strArray25[2]);
                
                string[] strArray21 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 slayerskill = new userInfo();
                slayerskill.Rank = Conversions.ToInteger(strArray21[0]);
                slayerskill.Level = Conversions.ToInteger(strArray21[1]);
                slayerskill.EXP = Conversions.ToInteger(strArray21[2]);
           
                string[] strArray9 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 farmingskill = new userInfo();
                farmingskill.Rank = Conversions.ToInteger(strArray9[0]);
                farmingskill.Level = Conversions.ToInteger(strArray9[1]);
                farmingskill.EXP = Conversions.ToInteger(strArray9[2]);
              
                string[] strArray20 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 runecraftingskill = new userInfo();
                runecraftingskill.Rank = Conversions.ToInteger(strArray20[0]);
                runecraftingskill.Level = Conversions.ToInteger(strArray20[1]);
                runecraftingskill.EXP = Conversions.ToInteger(strArray20[2]);
             
                string[] strArray14 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 hunterskill = new userInfo();
                hunterskill.Rank = Conversions.ToInteger(strArray14[0]);
                hunterskill.Level = Conversions.ToInteger(strArray14[1]);
                hunterskill.EXP = Conversions.ToInteger(strArray14[2]);
         
                string[] strArray4 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 constructionskill = new userInfo();
                constructionskill.Rank = Conversions.ToInteger(strArray4[0]);
                constructionskill.Level = Conversions.ToInteger(strArray4[1]);
                constructionskill.EXP = Conversions.ToInteger(strArray4[2]);
         
                string[] strArray24 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 summoningskill = new userInfo();
                summoningskill.Rank = Conversions.ToInteger(strArray24[0]);
                summoningskill.Level = Conversions.ToInteger(strArray24[1]);
                summoningskill.EXP = Conversions.ToInteger(strArray24[2]);
              
                string[] strArray8 = Regex.Replace(reader.ReadLine(), ",", " ").Split(new char[] { ' ' });
                 dungeoneeringskill = new userInfo();
                dungeoneeringskill.Rank = Conversions.ToInteger(strArray8[0]);
                dungeoneeringskill.Level = Conversions.ToInteger(strArray8[1]);
                dungeoneeringskill.EXP = Conversions.ToInteger(strArray8[2]);

                lblerror.Visible = false;


                SkillLevelShow();
                reader.Close();
                
            }
            catch (WebException exception1)
            {
                lblerror.Visible = true;

                ClearSkillLabels();
                if (exception1.Message.Contains("404"))
                {
                    this.lblerror.Text = @"The user '" + RSN + "' was not found."; 
                }         
            }
        }

        public void ClearSkillLabels()
        {
            //this.lblAttack.Text = "";
            //this.attackskill.Clear();
            //this.lblstrength.Text = "";
            //this.strengthskill.Clear();
            //this.lbldefence.Text = "";
            //this.defenceskill.Clear();
            //this.lblmagic.Text = "";
            //this.magicskill.Clear();
            //this.lblthieving.Text = "";
            //this.thievingskill.Clear();
            //this.lblhp.Text = "";
            //this.constitutionskill.Clear();
            //this.lblranging.Text = "";
            //this.rangeskill.Clear();
            //this.lblsummon.Text = "";
            //this.summoningskill.Clear();
            //this.lblcooking.Text = "";
            //this.cookingskill.Clear();
            //this.lblmine.Text = "";
            //this.miningskill.Clear();
            //this.lblprayer.Text = "";
            //this.prayerskill.Clear();
            //this.lblfiremaking.Text = "";
            //this.firemakingskill.Clear();
            //this.lblconstr.Text = "";
            //this.constructionskill.Clear();
            //this.lblcrafting.Text = "";
            //this.craftingskill.Clear();
            //this.lblfarm.Text = "";
            //this.farmingskill.Clear();
            //this.lblagility.Text = "";
            //this.agilityskill.Clear();
            //this.lblslayer.Text = "";
            //this.slayerskill.Clear();
            //this.lblsmith.Text = "";
            //this.smithingskill.Clear();
            //this.lblrunecrafting.Text = "";
            //this.runecraftingskill.Clear();
            //this.lblfletch.Text = "";
            //this.fletchingskill.Clear();
            //this.lblherb.Text = "";
            //this.herbloreskill.Clear();
            //this.lblfishing.Text = "";
            //this.fishingskill.Clear();
            //this.lblwc.Text = "";
            //this.woodcuttingskill.Clear();
            //this.lblhunt.Text = "";
            //this.hunterskill.Clear();
            //this.lbloverall.Text = "";
            //this.overallLevel.Clear();
            //this.lbldunegoneering.Text = "";
            //this.dungeoneeringskill.Clear();
            //this.lblSkillEXP.Text = "";
            //this.lblSkillName.Text = "";
            //this.lblSkillRank.Text = "";
            //this.lblXPtoLevel.Text = "";
            //this.lblcmb.Text = "";
        }
        public void SkillLevelShow()
        {
            //this.lblAttack.Text = Conversions.ToString(this.attackskill.TrueLevel());
            //this.lblstrength.Text = Conversions.ToString(this.strengthskill.TrueLevel());
            //this.lbldefence.Text = Conversions.ToString(this.defenceskill.TrueLevel());
            //this.lblmagic.Text = Conversions.ToString(this.magicskill.TrueLevel());
            //this.lblthieving.Text = Conversions.ToString(this.thievingskill.TrueLevel());
            //this.lblhp.Text = Conversions.ToString(this.constitutionskill.TrueLevel());
            //this.lblranging.Text = Conversions.ToString(this.rangeskill.TrueLevel());
            //this.lblsummon.Text = Conversions.ToString(this.summoningskill.TrueLevel());
            //this.lblcooking.Text = Conversions.ToString(this.cookingskill.TrueLevel());
            //this.lblmine.Text = Conversions.ToString(this.miningskill.TrueLevel());
            //this.lblprayer.Text = Conversions.ToString(this.prayerskill.TrueLevel());
            //this.lblfiremaking.Text = Conversions.ToString(this.firemakingskill.TrueLevel());
            //this.lblconstr.Text = Conversions.ToString(this.constructionskill.TrueLevel());
            //this.lblcrafting.Text = Conversions.ToString(this.craftingskill.TrueLevel());
            //this.lblfarm.Text = Conversions.ToString(this.farmingskill.TrueLevel());
            //this.lblagility.Text = Conversions.ToString(this.agilityskill.TrueLevel());
            //this.lblslayer.Text = Conversions.ToString(this.slayerskill.TrueLevel());
            //this.lblsmith.Text = Conversions.ToString(this.smithingskill.TrueLevel());
            //this.lblrunecrafting.Text = Conversions.ToString(this.runecraftingskill.TrueLevel());
            //this.lblfletch.Text = Conversions.ToString(this.fletchingskill.TrueLevel());
            //this.lblherb.Text = Conversions.ToString(this.herbloreskill.TrueLevel());
            //this.lblfishing.Text = Conversions.ToString(this.fishingskill.TrueLevel());
            //this.lblwc.Text = Conversions.ToString(this.woodcuttingskill.TrueLevel());
            
            //this.lblhunt.Text = Conversions.ToString(this.hunterskill.TrueLevel());
            //this.lbldunegoneering.Text = Conversions.ToString(this.dungeoneeringskill.TrueLevel());
            lbloverall.Text = Conversions.ToString(overallLevel.Level) + " (" + Conversions.ToString(VirtualLevel()) + ")";
            //this.lblcmb.Text = Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject(this.CombatLevel((double)this.constitutionskill.Level, (double)this.attackskill.Level, (double)this.strengthskill.Level, (double)this.defenceskill.Level, (double)this.summoningskill.Level, (double)this.prayerskill.Level, (double)this.rangeskill.Level, (double)this.magicskill.Level), " ("), this.CombatLevel((double)this.constitutionskill.TrueLevel(), (double)this.attackskill.TrueLevel(), (double)this.strengthskill.TrueLevel(), (double)this.defenceskill.TrueLevel(), (double)this.summoningskill.TrueLevel(), (double)this.prayerskill.TrueLevel(), (double)this.summoningskill.TrueLevel(), (double)this.magicskill.TrueLevel())), ")"));
        }
        public int VirtualLevel()
        {
            int num2 = 0;
            num2 += attackskill.TrueLevel();
            num2 += strengthskill.TrueLevel();
            num2 += defenceskill.TrueLevel();
            num2 += magicskill.TrueLevel();
            num2 += thievingskill.TrueLevel();
            num2 += constitutionskill.TrueLevel();
            num2 += rangeskill.TrueLevel();
            num2 += summoningskill.TrueLevel();
            num2 += cookingskill.TrueLevel();
            num2 += miningskill.TrueLevel();
            num2 += prayerskill.TrueLevel();
            num2 += firemakingskill.TrueLevel();
            num2 += constructionskill.TrueLevel();
            num2 += craftingskill.TrueLevel();
            num2 += farmingskill.TrueLevel();
            num2 += agilityskill.TrueLevel();
            num2 += slayerskill.TrueLevel();
            num2 += smithingskill.TrueLevel();
            num2 += runecraftingskill.TrueLevel();
            num2 += fletchingskill.TrueLevel();
            num2 += herbloreskill.TrueLevel();
            num2 += fishingskill.TrueLevel();
            num2 += woodcuttingskill.TrueLevel();
            num2 += hunterskill.TrueLevel();
            return (num2 + dungeoneeringskill.TrueLevel());
        }
        public object CombatLevel(double constit, double att, double str, double def, double smn, double prayer, double range, double magic)
        {
            double num = 0.25 * (((def + constit) + Math.Floor((double)(prayer / 2.0))) + Math.Floor((double)(smn / 2.0)));
            double num3 = 0.325 * (att + str);
            double num4 = 0.325 * Math.Floor((double)(range * 1.5));
            double num2 = 0.325 * Math.Floor((double)(magic * 1.5));
            return (num + Math.Max(num3, Math.Max(num4, num2)));
        }
    }
}
